// import { routerRedux } from 'dva/router';
import { message } from 'antd';
import { getSimilarData } from '@/services/evaluate';
import initChart from '@/utils/initChart';
import { generateTreeChartOption, generateSunburstChartOption } from '@/utils/echarts-figures.js';

const filterData = () => {};
export default {
  namespace: 'similarCompany',

  state: {
    staticChart: [],
    dynamicChart: {},
    staticDesc: '', // 静态相似指标解释
    dynamicDesc: '', // 动态相似指标解释
  },

  effects: {
    *getSimilar({ payload }, { call, put }) {
      try {
        const res = yield call(getSimilarData, payload);

        if (+res.code === 0) {
          for (let i = 0; i < res.data.charts.length; i++) {
            let item = res.data.charts[i];
            if (item.type === '静态相似') {
              yield put({
                type: 'setData',
                payload: {
                  staticChart: item.data,
                },
              });
            } else if (item.type === '动态相似') {
              yield put({
                type: 'setData',
                payload: {
                  dynamicChart: item.data,
                },
              });
            }
          }
          // 设置静态相似和动态性相似描述
          yield put({
            type: 'setData',
            payload: {
              staticDesc: res.data.desc.similar.static,
              dynamicDesc: res.data.desc.similar.dynamic,
            },
          });
        }
      } catch (e) {
        console.log(e);
        message.error('获取数据失败，请稍后再试');
        // yield put({type: "USER_FETCH_FAILED", message: e.message});
      }
    },
  },
  reducers: {
    setData(state, { payload }) {
      const newState = {
        ...state,
        ...payload,
      };
      return newState;
    },
  },
};
